﻿using Boco.CommonLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataSync.Common
{
    class TaskRunControl
    {
        private static IniHelper iniHelper = new IniHelper(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"TaskRun.ini"));

        public static int CheckTaskStatus(string taskid)
        {
            if (TaskConfig.IsTaskRunControl())
            {
                var str = iniHelper.IniReadValue(taskid, "Status");
                if (string.IsNullOrEmpty(str))
                {
                    return 0;
                }
                else
                {
                    return int.Parse(str);
                }
            }
            else
            {
                return 0;
            }
        }

        public static void StartTaskRun(string taskid)
        {
            if (TaskConfig.IsTaskRunControl())
            {
                iniHelper.IniWriteValue(taskid, "StartTime", DateTime.Now.ToString("G"));
                iniHelper.IniWriteValue(taskid, "EndTime", "");
                //iniHelper.IniWriteValue(taskid, "Result", "");
                iniHelper.IniWriteValue(taskid, "Status", "1");
            }
        }
        public static void StopTaskRun(string taskid)
        {
            if (TaskConfig.IsTaskRunControl())
            {
                //iniHelper.IniWriteValue(taskid, "StartTime", DateTime.Now.ToString("G"));
                iniHelper.IniWriteValue(taskid, "EndTime", DateTime.Now.ToString("G"));
                //iniHelper.IniWriteValue(taskid, "Result", "");
                iniHelper.IniWriteValue(taskid, "Status", "2");
            }
        }
    }
}
